<cfparam name="report" type="string" default="howDidWeDo" />
<cfif report eq "howDidWeDo">
	<cfset sourcePath = "http://" & cgi.HTTP_HOST & "/assets/calgrants/ui/printable/howDidWeDo.cfm" />
	<cfset targetDirectory = "C:\inetpub\assets\calgrants\reports\hdwd\" />
	<cfset targetPath = "http://" & cgi.HTTP_HOST & "/assets/calgrants/reports/hdwd/" />
	<cfset filenameRoot = "CashForCollege_HowDidWeDo_2013_" />
	<cfset qString = cgi.QUERY_STRING />
	<cfloop index="i" from="1" to="#ListLen(qString, '&')#">
		<cfset kvp = ListGetAt(qString, i, "&") />
		<cfif ListLast(ListFirst(kvp, "="), "_") eq "id">
			<cfset fileIdentifier = ListFirst(ListFirst(kvp, "="), "_") & "_" & ListLast(kvp, "=") />
			<cfbreak>
		</cfif>
	</cfloop>
	<cfif NOT IsDefined("fileIdentifier")>
		<cfset fileIdentifier = "Statewide" />
	</cfif>
	<cfset filename = filenameRoot & fileIdentifier & ".pdf" />
	<cfset sourceURL = sourcePath & "?" & cgi.QUERY_STRING />
	<cfset targetFile = targetDirectory & filename />
	<cfset targetURL = targetPath & filename />
</cfif>
<cfif IsDefined("targetFile") and IsDefined("targetURL")>
	<cfif NOT FileExists(targetFile)>
		<cfset pjsExe = "C:\Program Files (x86)\phantomjs\phantomjs.exe" />
		<cfset pjsScript = "C:\inetpub\assets\phantomjs\examples\rasterize.js" />
		<cfset pjsArgs = pjsScript & " " & sourceURL & " " & targetFile & " Letter" />
		<cfexecute name="#pjsExe#" arguments="#pjsArgs#" />
	<cfelse>
		<cflocation url="#targetURL#" addtoken="no">
		<cfabort>
	</cfif>
</cfif>

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<cfoutput>
		<meta http-equiv="refresh" content="15;URL=#targetURL#">
	</cfoutput>
	<title>Generating How Did We Do Report</title>
</head>
<body>
	<h1>Please wait while we generate the report</h1>
	<p>The How Did We Do Report can take up to 15 seconds to generate.  Once the report is ready, this page will refresh and open the report.</p>
</body>
</html>
<cfsetting showdebugoutput="no">
